package com.tms.permission.runner;

import com.tms.permission.service.PermissionSyncService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * 权限同步启动器
 * 在应用启动完成后立即执行权限同步
 */
@Component
@Order(1)  // 优先级，数字越小优先级越高
@Slf4j
public class PermissionSyncRunner implements ApplicationRunner {

//    private static final Logger logger = LoggerFactory.getLogger(PermissionSyncRunner.class);

    @Autowired
    private PermissionSyncService permissionSyncService;

    @Override
    public void run(ApplicationArguments args) {
        log.info("应用启动完成，开始执行权限数据初始化同步任务");
        try {
            // 执行全量同步
            permissionSyncService.fullSync();
            log.info("权限数据初始化同步任务执行完成");
        } catch (Exception e) {
            log.error("权限数据初始化同步任务执行异常", e);
            // 这里不抛出异常，避免影响应用启动
        }
    }
}
